<?php

namespace V2;
class C_CustomerFeedbackList extends \ResourceClass
{
    public $isActive = true;
    public $remark = '客户端意见反馈列表';

    /**
     * 获取回复列表
     * @param array $req
     * @param array $post
     * @param $result
     */
    public function get(array $req, array $post, &$result)
    {

        if (!isset($req['uid'])) {
            return 'require user id ';
        }
        if (!isset($req['userType'])) {
            return 'require user type';
        }
        if (!isset($req['k']) || !isset($req['t'])) {
            return 'data error';
        }
        $user_cls = \Biz\UserHandler::getById($req['userType'],$req['uid']);
        if(!is_object($user_cls) || $user_cls->getEnterpriseId() ==false){
            return 'data error';
        }
        $enterprise_id = $user_cls->getEnterpriseId();

        if (\Biz\UserHandler::checkAuth($req['userType'], $req['uid'], $enterprise_id, $req['t'], $req['k']) == false) {
            return 'data illegal';
        }
        $l = isset($req['l']) ? $req['l'] : 20;
        $o = isset($req['o']) ? $req['o'] : 0;
        try {

            $tabulation = new \Cls\Tabulation();
            /*$is_reply = $this->req->get('is_reply');
            if (isset($is_reply)) {
                $tabulation->setWhere('is_reply', $is_reply);
            }*/
            $tabulation->setOffset($o)
                ->setLimit($l)
                ->setOrderBy('insert_time', 'desc');
            $user_handler = new \Biz\CustomerFeedbackHandler();
            $user_handler->getFeedbackListByEnterpriseIdAndUid($enterprise_id, $req['uid'], $tabulation);

            $feedback_list = array();
            foreach ($tabulation->getData() as $feedback_cls) {
                $feedback = array();
                $feedback['id'] = $feedback_cls->getId();
                //$feedback['enterprise_id'] = $feedback_cls->getEnterpriseId();
                $feedback['user_name'] = $feedback_cls->getUserName();
                $feedback['user'] = $feedback_cls->getUser();
                $feedback['tel'] = $feedback_cls->getTel();
                $feedback['request'] = $feedback_cls->getContent();
                $feedback['request_time'] = $feedback_cls->getInsertTime();
                $feedback['is_response']=$feedback_cls->getIsReply();
                $feedback['is_read'] = $feedback_cls->getIsRead();
                /*$feedback['response'] = ($feedback_cls->getIsReply() == 0) ? '' : $feedback_cls->getReply();
                $feedback['response_time'] = ($feedback_cls->getIsReply() == 0) ? '' : $feedback_cls->getReplyTime();
                if (is_object($feedback_cls) && $feedback_cls->getFeedbackImageList() != false) {
                    foreach ($feedback_cls->getFeedbackImageList() as $feedbackimg) {
                        $imglist = array(
                            'imgurl' => $feedbackimg->getUrl(),
                        );
                        $feedback['img_list'][] = $imglist;
                    }
                }
                if (is_object($feedback_cls) && $feedback_cls->getFeedbackDialogList() != false) {
                    foreach ($feedback_cls->getFeedbackDialogList() as $feedbackdialog) {
                        $feedback_diolog = array(
                            'feedback_id' => $feedbackdialog->getFeedbackId(),
                            'request' => $feedbackdialog->getContent(),
                            'request_time' => $feedbackdialog->getInsertTime(),
                            'is_response' => $feedbackdialog->getIsReply(),
                            'response' => ($feedbackdialog->getIsReply() == 0) ? '' : $feedbackdialog->getReply(),
                            'response_time' => ($feedbackdialog->getIsReply() == 0) ? '' : $feedbackdialog->getReplyTime(),
                        );
                        $feedback['feedback_diolog'][] = $feedback_diolog;
                    }
                }*/
                $feedback_list[] = $feedback;
            }
            $result['feedback_list'] = $feedback_list;

        } catch (Exception $e) {
            return $e->getMessage();
        }

    }
}